package com.yscp.ysdemo.constant;

/**
 * 存各种key的前缀和生成
 */
public final class RedisConstant {
    public static final String sep = ":";
    public static final String LOGIN_TOKEN = "token";
    public static final Integer RESULT_FIRST_SAVE = 2;
    public static final Integer RESULT_SUCCESS = 1;
    public static final Integer RESULT_ERROR = -1;


    public static String getLoginToken(String userId){
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(LOGIN_TOKEN).append(sep).append(userId);
        return stringBuffer.toString();
    }

    /**
     * 点赞hash总表的key————实体类型：实体id：点赞的用户
     */
    public static String getLikeRelationKey(String entityId,String type,String userId){
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(type).append(sep).append(entityId).append(sep).append(userId);
        return stringBuffer.toString();
    }

    /**
     *  点赞数量hash总表的key————实体类型：实体id
     */
    public static String getEntityLikeCountKey(String entityId,String type){
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(type).append(sep).append(entityId);
        return stringBuffer.toString();
    }

    /**
     *  关注hash总表的key————被关注的实体类型：被关注的实体id：关注的用户
     */
    public static String getFocusRelationKey(String entityId,String type,String userId){
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(type).append(sep).append(entityId).append(sep).append(userId);
        return stringBuffer.toString();
    }



    /**
     *ZSet关注列表key
     * @param userId 点击关注的用户id
     * @return FocusUser：点击关注的用户id：关注的实体类型
     */
    public static String getFocusUserKey(String userId,String type){
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("FocusUser").append(sep).append(userId).append(sep).append(type);
        return stringBuffer.toString();
    }

    /**
     *ZSet粉丝列表key
     * @param userId userId 被关注的用户id
     * @return FanUser：被关注的用户id
     */
    public static String getFanUserKey(String userId){
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("FanUser").append(sep).append(userId);
        return stringBuffer.toString();
    }




    /**
     * 收藏hash总表的key————实体类型：实体id：用户id
     * @param entityId
     * @param type
     * @param userId
     * @return
     */
    public static String getCollectRelationKey(String entityId,String type,String userId){
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(type).append(sep).append(entityId).append(sep).append(userId);
        return stringBuffer.toString();
    }

    /**
     * 每个用户维护的收藏列表zset的key————collect：实体类型：userid
     * @param entityId
     * @param type
     * @param userId
     * @return
     */
    public static String getCollectKey(String entityId,String type,String userId){
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("collect").append(sep).append(type).append(sep).append(entityId).append(sep).append(userId);
        return stringBuffer.toString();
    }
}
